/*******************************************************************************

This code file produces Figure A16, "Evolution of Estimated Taxable Shares over Building Lifecycle."

*******************************************************************************/

*** Manage settings

	run "$dir/code/modules/settings.do"
	
********************************************************************************
* Graph distribution assessed values over time
********************************************************************************
	
	use "$data/raw/assessments/av_fraction_history.dta", clear

*** Rescale into taxable shares of assessed value

	bys bbl: gegen maxf = max(f)
	replace identifier = 1 if maxf < 0.061

	collapse (median) p50=fraction (p25) p25=fraction (p75) p75=fraction, by(identifier age)
		
	foreach v of varlist p50 p25 p75 {
		replace `v' = `v'/0.06 if identifier == 1
	}	
	
	foreach v of varlist p50 p25 p75 {
		replace `v' = `v'/0.45 if identifier == 2 | identifier == 3
	}
	
*** Make graph			
	
	gr drop _all
	
	tw line p50 p25 p75 age if identifier == 1, xline(15, lcolor(gs9) lpattern(dash)) name(gr0) ///
		graphregion(color(white)) legend(order(1 "Median" 2 "25th Percentile" 3 "75th Percentile") rows(1)) ///
		ytitle("Taxable Share of Assessed Value") xtitle("Years Since Completion") ///
		subtitle("Class 1 Building (3 Units)")
		
	tw line p50 p25 p75 age if identifier == 2, xline(15, lcolor(gs9) lpattern(dash)) name(gr1) ///
		graphregion(color(white)) legend(order(1 "Median" 2 "25th Percentile" 3 "75th Percentile") rows(1)) ///
		ytitle("Taxable Share of Assessed Value") xtitle("Years Since Completion") ///
		subtitle("Class 2 Building (4-10 Units)")
		
	tw line p50 p25 p75 age if identifier == 3, xline(15, lcolor(gs9) lpattern(dash)) name(gr2) ///
		graphregion(color(white)) legend(order(1 "Median" 2 "25th Percentile" 3 "75th Percentile") rows(1)) ///
		ytitle("Taxable Share of Assessed Value") xtitle("Years Since Completion") ///
		subtitle("Class 2 Building (11+ Units)")
			
	grc1leg gr0 gr1 gr2, ycommon graphregion(color(white)) rows(1)
			
	graph export "$figs/sh_taxable_av.pdf", replace
	graph export "$figs_overleaf/sh_taxable_av.pdf", replace
	
	graph close _all
